/**
 * This file is part of the CAKIS project.
 * 
 * Copyright (c) 2009-2010 - Florian Arndt, Christian Kerl
 * 
 * @license GNU Lesser General Public License v3 <http://www.opensource.org/licenses/lgpl-3.0.html>
 * @since   27.04.2010
 * @version SVN: $Id: ProductListRepositoryImpl.java 97 2010-04-28 10:41:34Z christian-kerl@web.de $
 */
package org.cakis.server.model.repository.impl;

import java.util.List;

import javax.ejb.Stateless;
import javax.persistence.Query;

import org.cakis.server.Names;
import org.cakis.server.model.ProductList;
import org.cakis.server.model.repository.ProductListRepository;
import org.jboss.seam.annotations.AutoCreate;
import org.jboss.seam.annotations.Name;

/**
 * ProductListRepositoryImpl
 *
 * @author Christian Kerl
 */
@Name(Names.ProductListRepository)
@AutoCreate
@Stateless(name=Names.ProductListRepository)
public class ProductListRepositoryImpl extends AbstractRepository<ProductList> implements ProductListRepository {

    @Override
    protected Long getId(ProductList object) {
        return object.getId();
    }

    @Override
    public ProductList findByIdAndFetch(Long id) {
        Query q = em.createQuery("select pl from ProductList pl left join fetch pl.entries where pl.id=:id");
        q.setParameter("id", id);

        return one(q);
    }

    @Override
    public List<ProductList> findNonArchived() {
        Query q = em.createQuery("select pl from ProductList pl where pl.isArchived != true");

        return list(q);
    }

}
